import {HIDE_LOADING, SHOW_LOADING, LOGIN, LOGINOUT} from "./types";

const state = {
  loading: false,
  token: null
};


const mutations = {
  [HIDE_LOADING](state) {
    state.loading = false;
  },
  [SHOW_LOADING](state) {
    state.loading = true;
  },
  [LOGIN](state, token) {
    state.token = token;
    window.localStorage.setItem('AppToken', token);
  },
  [LOGINOUT](state) {
    state.token = null;
    window.localStorage.removeItem('AppToken');
  }
}


const getters = {
  loading(state) {
    return state.loading
  }
}


export default {
  state,
  mutations,
  getters
}
